/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.*;

/**
 *
 * @author DomKvic
 */
public class AppleDAO {

    public static List<Apple> getAll() {
        List<Apple> list = null;
        Session session = util.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        String hql = "from Apple";
        Query query = session.createQuery(hql);
        list = query.list();
        session.close();
        return list;
    }
    
    public static List<Apple> getAllMac() {
        List<Apple> list = null;
        Session session = util.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        String hql = "from Apple where typeofapple.idtypeOfApple = 1";
        Query query = session.createQuery(hql);
        list = query.list();
        session.close();
        return list;
    }
    
    public static List<Apple> getAlliPod() {
        List<Apple> list = null;
        Session session = util.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        String hql = "from Apple where typeofapple.idtypeOfApple = 2";
        Query query = session.createQuery(hql);
        list = query.list();
        session.close();
        return list;
    }
    
    public static List<Apple> getAlliPhone() {
        List<Apple> list = null;
        Session session = util.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        String hql = "from Apple where typeofapple.idtypeOfApple = 3";
        Query query = session.createQuery(hql);
        list = query.list();
        session.close();
        return list;
    }
    
    public static List<Apple> getAlliPad() {
        List<Apple> list = null;
        Session session = util.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        String hql = "from Apple where typeofapple.idtypeOfApple = 4";
        Query query = session.createQuery(hql);
        list = query.list();
        session.close();
        return list;
    }
}
